<template>
  <div class="shop-container">
    <!-- 左侧隐藏菜单 -->
    <el-drawer
      v-model="drawerVisible"
      :with-header="false"
      :size="240"
      :before-close="handleClose"
    >
      <el-menu
        :default-active="$route.path"
        mode="vertical"
        @select="handleMenuSelect"
      >
        <el-menu-item index="/shop/products">商品列表</el-menu-item>
        <el-menu-item index="/shop/cart">购物车</el-menu-item>
        <el-menu-item index="/shop/promotion">促销活动</el-menu-item>
        <el-menu-item index="/shop/recommendations">猜你喜欢</el-menu-item>
      </el-menu>
    </el-drawer>

    <!-- 主内容区域 -->
    <div class="main-content">
      <el-header class="header">
        <el-row type="flex" justify="space-between">
          <el-col :span="16">
            <h1>商城首页</h1>
          </el-col>
          <el-col :span="8">
            <el-button type="text" @click="drawerVisible = true">☰ 菜单</el-button>
          </el-col>
        </el-row>
      </el-header>

      <router-view class="content-area" />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const drawerVisible = ref(false)

// const handleMenuSelect = (key: string) => {
//   router.push(key).catch(err => {
//     if (!err.message.includes('Avoided redundant navigation')) throw err
//   })
// }

const handleClose = () => {
  drawerVisible.value = false
}
</script>

<style scoped>
.shop-container {
  height: 100vh;
}

.main-content {
  padding: 20px;
  margin-left: 60px; /* 为移动端留出空间 */
}

.header {
  padding: 20px 0;
  border-bottom: 1px solid #eee;
}

.el-drawer {
  background: #f5f7fa;
}

@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
  }
  
  .el-drawer {
    width: 100% !important;
  }
}
</style>